Skip to content

perf: cache hidden post set in Redis to prevent DB pool exhaustion#370

Open
ety001 wants to merge 1 commit intomasterfrom
perf/hive-posts-status-indexes
Open

perf: cache hidden post set in Redis to prevent DB pool exhaustion#370
ety001 wants to merge 1 commit intomasterfrom
perf/hive-posts-status-indexes

Conversation

@ety001
Copy link
Copy Markdown
Member

@ety001 ety001 commented Apr 20, 2026

The hide_pids_by_ids function was querying hive_posts_status on every API request with 'WHERE list_type=1 AND post_id IN :ids'. Even though the table is small (13K rows, 832KB) and has proper indexes, under burst traffic this flooded the DB connection pool (size=30), causing cascading timeouts up to 427 seconds.

Confirmed via production RDS debug API (2026-04-20):

  • hive_posts_status: 13,764 rows, indexes exist and healthy
  • DB version: 27 (all migrations applied)
  • Scalyr showed 0.0% idle during peak, 56 queries >100s (pool queuing)

Fix: Cache the full hidden post ID set in Redis (60s TTL) and filter in Python. This turns every hide_pids_by_ids call into a Redis lookup

  • Python set intersection, eliminating the DB query entirely.

The hide_pids_by_ids function was querying hive_posts_status on every
API request with 'WHERE list_type=1 AND post_id IN :ids'. Even though
the table is small (13K rows, 832KB) and has proper indexes, under burst
traffic this flooded the DB connection pool (size=30), causing cascading
timeouts up to 427 seconds.

Confirmed via production RDS debug API (2026-04-20):
- hive_posts_status: 13,764 rows, indexes exist and healthy
- DB version: 27 (all migrations applied)
- Scalyr showed 0.0% idle during peak, 56 queries >100s (pool queuing)

Fix: Cache the full hidden post ID set in Redis (60s TTL) and filter
in Python. This turns every hide_pids_by_ids call into a Redis lookup
+ Python set intersection, eliminating the DB query entirely.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant